package com.ghsc.ghxc.jsb.ui.live.view

import android.content.Context
import android.util.AttributeSet
import android.widget.FrameLayout
import com.aliyun.aliinteraction.uikit.core.BaseComponent
import com.aliyun.aliinteraction.uikit.core.ComponentHolder
import com.aliyun.aliinteraction.uikit.core.IComponent
import com.aliyun.auipusher.LiveContext
import com.cn.appcore.event.RxBus
import com.cn.appcore.event.RxBusBean
import com.ghsc.ghxc.jsb.R
import com.ghsc.ghxc.jsb.config.CustSignKey
import com.ghsc.ghxc.jsb.ui.live.bean.CustImNoticeBean

/**
 * @author 礼物
 * @version 2021/7/29
 */
class LiveGifView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr), ComponentHolder {
    private val component: Component = Component()
    override fun getComponent(): IComponent {
        return component
    }

    private inner class Component : BaseComponent() {
        var bean: CustImNoticeBean? =null
        override fun onInit(liveContext: LiveContext) {
            super.onInit(liveContext)
            visibility = if (isOwner) GONE else VISIBLE
            bean=CustImNoticeBean(liveContext.liveModel.anchorId,liveContext.groupId)
        }
        fun handleShareClick() {
            RxBus.getDefault().post(
                RxBusBean(
                    CustSignKey.CUST_LIVE_GIF_PW,
                    CustSignKey.CUST_LIVE_GIF_PW,bean!!)
            )
        }

        override fun onActivityDestroy() {
        }
    }

    init {
        inflate(context, R.layout.ilr_view_live_gif, this)
        setOnClickListener { component.handleShareClick() }
    }
}